package com.imonsoft.sqm.dao.sys;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.imonsoft.common.httpModel.DataGrid;
import com.imonsoft.common.httpModel.Pager;
import com.imonsoft.sqm.pojo.sys.User;
import com.imonsoft.sqm.pojo.sys.UserExample;

@SuppressWarnings("deprecation")
@Repository("userDAO")
public class UserDAOImpl extends SqlMapClientDaoSupport implements UserDAO {

    /**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public UserDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int countUserByExample(UserExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"ts_user.ibatorgenerated_countByExample", example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int deleteUserByExample(UserExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"ts_user.ibatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int deleteUserByPrimaryKey(Long id) {
		User key = new User();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete(
				"ts_user.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public Long insertUser(User record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"ts_user.ibatorgenerated_insert", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public Long insertUserSelective(User record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"ts_user.ibatorgenerated_insertSelective", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	@SuppressWarnings("unchecked")
	public List<User> selectUserByExample(UserExample example) {
		List<User> list = getSqlMapClientTemplate().queryForList(
				"ts_user.ibatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public User selectUserByPrimaryKey(Long id) {
		User key = new User();
		key.setId(id);
		User record = (User) getSqlMapClientTemplate().queryForObject(
				"ts_user.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int updateUserByExampleSelective(User record, UserExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"ts_user.ibatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int updateUserByExample(User record, UserExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"ts_user.ibatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int updateUserByPrimaryKeySelective(User record) {
		int rows = getSqlMapClientTemplate().update(
				"ts_user.ibatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	public int updateUserByPrimaryKey(User record) {
		int rows = getSqlMapClientTemplate().update(
				"ts_user.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table ts_user
	 * @ibatorgenerated  Sat Jun 01 11:54:50 CST 2013
	 */
	private static class UpdateByExampleParms extends UserExample {
		private Object record;

		public UpdateByExampleParms(Object record, UserExample example) {
			super(example);
			this.record = record;
		}

		@SuppressWarnings("unused")
		public Object getRecord() {
			return record;
		}
	}

	@SuppressWarnings("unchecked")
    public DataGrid<User> getDataGrid(UserExample example, Pager pager) {
        if (example == null) {
            example = new UserExample();
        }
        int total = countUserByExample(example);
        List<User> rows = getSqlMapClientTemplate().queryForList("ts_user.ibatorgenerated_selectByExample", example, pager.getSkipResults(), pager.getRows());
        DataGrid<User> dataGrid = new DataGrid<User>(total, rows);
        return dataGrid;
    }
}